package com.huawei.hms.support.api.opendevice;

import com.huawei.hms.api.HuaweiApiClient;
import com.huawei.hms.core.aidl.IMessageEntity;
import com.huawei.hms.support.api.PendingResultImpl;
import com.huawei.hms.support.api.client.PendingResult;
import com.huawei.hms.support.api.client.Result;
import com.huawei.hms.support.api.client.Status;
import com.huawei.hms.support.api.entity.opendevice.HuaweiOpendeviceNaming;
import com.huawei.hms.support.api.entity.opendevice.OaidReq;
import com.huawei.hms.support.api.entity.opendevice.OaidResp;
import com.huawei.hms.support.api.entity.opendevice.OdidReq;
import com.huawei.hms.support.api.entity.opendevice.OdidResp;
import com.huawei.hms.support.log.HMSLog;

public class HuaweiOpendeviceApiImpl implements HuaweiOpendeviceApi {
    public PendingResult<OaidResult> getOaid(HuaweiApiClient huaweiApiClient) {
        HMSLog.i("OpenIdentifierApiImpl", "Enter getOaid");
        return new PendingResultImpl<OaidResult, OaidResp>(this, huaweiApiClient, HuaweiOpendeviceNaming.getOaid, new OaidReq()) {
            final /* synthetic */ HuaweiOpendeviceApiImpl a;

            public /* synthetic */ Result onComplete(IMessageEntity iMessageEntity) {
                return a((OaidResp) iMessageEntity);
            }

            public OaidResult a(OaidResp oaidResp) {
                if (oaidResp == null) {
                    HMSLog.e("OpenIdentifierApiImpl", "getOaid OaidResp is null");
                    return null;
                }
                Status commonStatus = oaidResp.getCommonStatus();
                if (commonStatus == null) {
                    HMSLog.e("OpenIdentifierApiImpl", "getOaid commonStatus is null");
                    return null;
                }
                HMSLog.i("OpenIdentifierApiImpl", "getOaid onComplete:" + commonStatus.getStatusCode());
                OaidResult oaidResult = new OaidResult();
                oaidResult.setStatus(commonStatus);
                oaidResult.setId(oaidResp.getId());
                oaidResult.setTrackLimited(oaidResp.isTrackLimited());
                oaidResult.setSettingIntent(oaidResp.getSettingIntent());
                return oaidResult;
            }
        };
    }

    public PendingResult<OdidResult> getOdid(HuaweiApiClient huaweiApiClient) {
        HMSLog.i("OpenIdentifierApiImpl", "Enter getOdid");
        return new PendingResultImpl<OdidResult, OdidResp>(this, huaweiApiClient, HuaweiOpendeviceNaming.getOdid, new OdidReq()) {
            final /* synthetic */ HuaweiOpendeviceApiImpl a;

            public /* synthetic */ Result onComplete(IMessageEntity iMessageEntity) {
                return a((OdidResp) iMessageEntity);
            }

            public OdidResult a(OdidResp odidResp) {
                if (odidResp == null) {
                    HMSLog.e("OpenIdentifierApiImpl", "getOdid OaidResp is null");
                    return null;
                }
                Status commonStatus = odidResp.getCommonStatus();
                if (commonStatus == null) {
                    HMSLog.e("OpenIdentifierApiImpl", "getOdid commonStatus is null");
                    return null;
                }
                HMSLog.i("OpenIdentifierApiImpl", "getOdid onComplete:" + commonStatus.getStatusCode());
                OdidResult odidResult = new OdidResult();
                odidResult.setStatus(commonStatus);
                odidResult.setId(odidResp.getId());
                return odidResult;
            }
        };
    }
}
